package com.zhaotianhao.serviceproduct.controller;


import com.github.pagehelper.PageInfo;
import com.zhaotianhao.serviceproduct.common.JsonResult;
import com.zhaotianhao.serviceproduct.dto.SpuQueryDTO;
import com.zhaotianhao.serviceproduct.service.ISpuService;
import com.zhaotianhao.serviceproduct.vo.SkuDetailVO;
import com.zhaotianhao.serviceproduct.vo.SpuListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * spu表，该表描述的是一个抽象性的商品，比如 iphone8 前端控制器
 * </p>
 *
 * @author Z-7
 * @since 2022-04-27
 */
@RestController
@RequestMapping("/spu")
public class SpuController {

    @Autowired
    private ISpuService iSpuService;

    /**
     * 列表页接口
     * @param spuQueryDTO
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public JsonResult getListSpu(SpuQueryDTO spuQueryDTO , @RequestParam(name = "pageNum",defaultValue = "1") int pageNum ,@RequestParam(name = "pageSize",defaultValue = "16") int pageSize) {
        PageInfo<SpuListVO> page = iSpuService.getPageInfo(spuQueryDTO,pageNum,pageSize);
        return JsonResult.successd(page);
    }

    @PostMapping("skuDetail/{skuId}")
    public JsonResult getSkuDetailBySkuId(@PathVariable(name = "skuId") long skuId) {
        System.out.println(skuId);
        SkuDetailVO skuDetailVO = iSpuService.getSkuBySkuId(skuId);
        return JsonResult.successd(skuDetailVO);
    }
}
